<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use common\models\customInfo\CustomInfo;
/* @var $this yii\web\View */
/* @var $searchModel common\models\customInfo\CustomInfoSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', '报名列表');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('siderbar'); ?>
<?= $this->render('//layouts/act-menu') ?>
<?php $this->endBlock(); ?>
<div class="custom-info-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
    <p>
        <?= Html::a(Yii::t('app', '添加报名'), ['create','id'=>$id], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'info_id',
            [
                'attribute' => 'sub_info',
                'label' => '姓名',
                'format' => 'html',
                'value' => function ($model) {
                    $sub_info = unserialize($model->sub_info);
                    foreach ($sub_info as $key => $value) {
                        if($value['name']=="姓名")
                        {
                            return '<td>' . $value['value'] . '</td>';
                        }
                    }
                },
            ],
            [
                'attribute' => 'sub_info1',
                'label' => '手机号',
                'format' => 'html',
                'value' => function ($model) {
                    $sub_info = unserialize($model->sub_info);
                    foreach ($sub_info as $key => $value) {
                        if($value['type']=="phone")
                        {
                            return '<td>' . $value['value'] . '</td>';
                        }
                    }
                },
            ],
            [
                'attribute' => 'sub_info2',
                'label' => '邮箱',
                'format' => 'html',
                'value' => function ($model) {
                    $sub_info = unserialize($model->sub_info);
                    foreach ($sub_info as $key => $value) {
                        if($value['type']=="email")
                        {
                            return '<td>' . $value['value'] . '</td>';
                        }
                    }
                },
            ],
            [
                'attribute' => 'add_time',
                'format' => ['date', 'Y-M-d H:i:s'],
            ],
            [
                'attribute' => 'status',
                'format' => 'html',
                'value' => function ($model) {
                    if ($model->status === $model::STATUS_SUCCESS) {
                        $class = 'label-success';
                    } elseif ($model->status === $model::STATUS_DAIZHIFU) {
                        $class = 'label-warning';
                    } else {
                        $class = 'label-danger';
                    }

                    return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>';
                },
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>CustomInfo::getArrayStatus(),
                'filterWidgetOptions'=>[
                    'pluginOptions'=>['allowClear'=>true],
                ],
                'filterInputOptions'=>['placeholder'=>'全部'],
                'format'=>'raw'

            ],
            // 'user_name',
            // 'phone',
            // 'sub_info:ntext',
            // 'work',
            // 'user_id',
            // 'status',
            // 'code',

            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作', 
                'template' => '{view}{delete}',
                'headerOptions' => ['width' => '200'],
                'buttons' => [
                    'view' => function ($url, $model, $key) {
                        return  Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-eye-open" ><span class="classformat">查看</span></span>', $url, ['title' => '查看'] ) ;
                    },
                    /*'update' => function ($url, $model, $key) {
                        return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-pencil"><span class="classformat">修改</span></span>', $url, ['title' => '修改'] ) ;
                    },*/
                    'delete' => function ($url, $model, $key) {
                        return Html::a('&nbsp;&nbsp;<span class="glyphicon glyphicon-trash" ><span class="classformat">删除</span></span>', $url, [
                            'title' => '删除',
                            'data'=>[
                                'confirm'=>'你确定要删除吗？',
                                'method'=>'post'
                            ]
                        ] ) ;
                    },
                ],
            ],
        ],
    ]); ?>
</div>